package DAO;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import Entity.Market;

public class MarketDAO {

	private MarketDAO() {
	}

	public static void create(Market nuevo, EntityManager em) {
		em.persist(nuevo);
	}

	@SuppressWarnings("unchecked")
	public static List<Market> readMarkets(EntityManager em) {
		Query query = em.createQuery("SELECT market FROM MARKET market");
		return (List<Market>) query.getResultList();
	}

	public static void update(Market old, EntityManager em) {
		em.merge(old);
	}

	public static void delete(Market market, EntityManager em) {
		em.remove(market);
	}

	public static Market find(Market company, EntityManager em) {
		// TODO Auto-generated method stub
		return em.find(company.getClass(), company.getId());
	}

}
